package com.yangyang.androidconnect.controller;

import com.alibaba.fastjson.JSONObject;
import com.yanzhenjie.andserver.annotation.GetMapping;
import com.yanzhenjie.andserver.annotation.RequestMapping;
import com.yanzhenjie.andserver.annotation.RestController;
import com.yanzhenjie.andserver.http.HttpRequest;

@RestController
@RequestMapping(path = "/client")
public class ClientController {

    @GetMapping(path = "/connection")
    public JSONObject getConnection(HttpRequest request) {
        String localAddr = request.getLocalAddr();// HostAddress
        String localName = request.getLocalName();// HostName
        int localPort = request.getLocalPort();// server's port

        String remoteAddr = request.getRemoteAddr();// HostAddress
        String remoteHost = request.getRemoteHost();// Especially HostName, second HostAddress
        int remotePort = request.getRemotePort();// client's port

        JSONObject object = new JSONObject(true);
        object.put("localAddr", localAddr);
        object.put("localName", localName);
        object.put("localPort", localPort);
        object.put("remoteAddr", remoteAddr);
        object.put("remoteHost", remoteHost);
        object.put("remotePort", remotePort);
        return object;
    }
}